<?php

namespace app\utils;
class Axios
{
    static function post($url, $params)
    {
        $postData = http_build_query($params);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type:application/x-www-form-urlencoded',
                'content' => $postData,
                'timeout' => 15 * 60 // 超时时间（单位:s）
            )
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        return json_decode($result,true);
    }

    static function get($url)
    {
        $client = new \GuzzleHttp\Client();
        $response = $client->request('GET', $url);
        if ($response->getStatusCode() == 200) {
            return [
                "success" => true,
                'data' => $response->getBody()
            ];
        }
        return [
            "success" => false,
            'data' => $response->getBody(),
        ];
    }
}